package com.mall.order.config;

import com.mall.order.constants.RocketMQConstants;
import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.exception.RemotingException;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MyRocketMQConfig {
    /**
     * 消息处理者
     */
    public void handle(){

    }

    /**
     * 发送延迟消息
     */
    public void sendDelayMsg(String orderSN) throws MQClientException, MQBrokerException, RemotingException, InterruptedException {
        DefaultMQProducer producer = new DefaultMQProducer("ExampleProductGroup");
        producer.setNamesrvAddr(RocketMQConstants.nameSer);
        producer.start();
        int totalMessagesToSend = 100;
        for (int i = 0;i < totalMessagesToSend;i++){
            Message message = new Message(RocketMQConstants.orderTopic, orderSN.getBytes());
            message.setDelayTimeLevel(4);
            producer.send(message);
        }
        producer.shutdown();
    }
}
